//
//  XQAlbumCellCollectionViewCell.swift
//  PhotoSelect
//
//  Created by 王帅强 on 2019/1/7.
//  Copyright © 2019 王帅强. All rights reserved.
//

import UIKit
import Photos

class XQAlbumCell: UICollectionViewCell {

    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var numLabel: UILabel!


    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func configData(album: XQAlbumModel) {
        nameLabel.text = album.name
        numLabel.text = "\(album.count)"
        configImage(album: album)
    }

    func configImage(album: XQAlbumModel)  {
        guard let asset = album.assetsResult?.lastObject else {
            return
        }

        let options: PHImageRequestOptions = PHImageRequestOptions.init()
        options.resizeMode = .fast
        options.deliveryMode = .highQualityFormat
        options.isNetworkAccessAllowed = true
        PHCachingImageManager.default().requestImage(for: asset, targetSize: CGSize(width: 300, height: 300), contentMode: .aspectFill, options: options) { (result, info) in
            self.imageView.image = result
        }

    }
}
